﻿using System.Collections.Generic;
using Gp.Scripts.Core;

namespace Gp.Scripts.Core
{
    // public class StatProperty {
    //     public string Name;
    //     public string NumericValue;
    // }
    public abstract class GameEntityStat
    {
        /// <summary>
        /// Property - 
        /// </summary>
        protected readonly Dictionary<int, IntValue> ValueDic = new();

        public int this[int id]
        {
            get => ValueDic.TryGetValue(id, out var res) ? res.Value : 0;
            set
            {
                if (ValueDic.TryGetValue(id, out var num))
                {
                    num.Value = value;
                }
                else
                {
                    ValueDic[id] = new IntValue(value);
                }
            }
        }


        public int this[StatField field]
        {
            get => ValueDic.TryGetValue(field.StatId(), out var res) ? res.Value : 0;
            set
            {
                if (ValueDic.TryGetValue(field.StatId(), out var num))
                {
                    num.Value = value;
                }
                else
                {
                    ValueDic[field.StatId()] = new IntValue(value);
                }
            }
        }


        /// <summary>
        /// 获得对应数值的包装类，主要用于值监听。
        /// </summary>
        /// <param name="statId"></param>
        /// <returns></returns>
        public IntValue GetValueWrapper(int statId)
        {
            return ValueDic.GetValueOrDefault(statId);
        }


        public IntValue GetValueWrapper(StatField field)
        {
            return GetValueWrapper(field.StatId());
        }
    }
}